package Classes.GameViews.ViewPanels
{
	import Classes.GameViews.ViewScenes.VS_Main;
	
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.system.ApplicationDomain;

	/** 
	 * @author thy
	 * @version 1.0.0 
	 * 创建时间：Jun 28, 2012 3:41:26 PM 
	 */ 
	public class VP_PorgramNpcDialogue extends ViewPanel
	{
		private static var _instance:VP_PorgramNpcDialogue;
		
		private var _interfaceUI:Sprite;
		private var callFun:Function;
		/**
		 * 是否已经打开了这个页面 
		 */		
		public static var isOpenProgramDialogue:Boolean=false;
		
		public function VP_PorgramNpcDialogue()
		{
			init();
		}
		
		private function init():void
		{
			this._interfaceUI=new (ApplicationDomain.currentDomain.getDefinition("PorgramNpcDialogue_v") as Class);
			this.addChild(this._interfaceUI);
			this.addListener();
		}
		
		
		private function addListener():void
		{
			this.addEventListener("closeNpcDialogue",clickHandler);
		}
		
		/**
		 * 给进度弹框赋值 
		 * @param title
		 * @param context
		 * @param contextPic
		 * @param jindu
		 * @param callBackFun
		 */		
		public function setPorgramNpcDialogueInfo(title:DisplayObject=null,context:String="",contextPic:DisplayObject=null,jindu:int=0,callBackFun:Function=null):void
		{
			callFun=callBackFun;
			this._interfaceUI["setPorgramNpcDialogueInfo"](title,context,contextPic,jindu);
		}
		
		/**
		 * 控制进度条 
		 * @param value
		 */		
		public function controlProgramBar(value:int):void
		{
			this._interfaceUI["controlProgramBar"](value);
		}
		
		/**
		 * 打开进度弹框
		 */		
		public function openNpc():void
		{
			this.openAt(VS_Main.instance,true);
			this.toCenter();
		}
		
		
		private function clickHandler(e:Event):void
		{
			if(callFun==null)
			{
				this.closeWin();
			}else{
				callFun();
			}
		}
		
		/**
		 *关闭界面 
		 */		
		public function closeWin():void
		{
			this.close();
		}
		
		public static function get instance():VP_PorgramNpcDialogue
		{
			if(!_instance)_instance=new VP_PorgramNpcDialogue();
			return _instance;
		}
		
		public function get interfaceUI():Sprite
		{
			return _interfaceUI;
		}
	}
}
